(function() {
// 添加创建主题按钮
  const style = {
      '.createTheme': {
        position: 'fixed', left: '50%', top: '50%', padding: '20px',
        display: 'block', width: '460px', transform: 'translate(-50%, -50%)',
        background: '#0089AA', color: '#fff', overflow: 'auto',
        'font-size': '16px', 'border-radius': '18px'
      },
      '.createTheme .label': { 'margin-bottom': '10px', 'text-align': 'center' },
      '.createTheme p': { 'margin-bottom': '5px' },
      '.createTheme input': { padding: '3px 6px' },
      '.createTheme button': { margin: '0 5px', padding: '6px', cursor: 'pointer' },
      '.createTheme .result': { 'text-align': 'center', 'font-size': '12px' }
    },
    openCreateThemeBtn = $('<a class="fr" href="javascript:void(0)">创建主题</a>'),
    createThemeEl = $(
      '<div class="createTheme" style="max-height:' + (window.innerHeight - 40) + 'px">' +
      ' <div class="label">主题名称：<input class="theme"></div>' +
      ' <div class="label">开始序号：<input class="start" value="1"></div>' +
      ' <div class="label">创建个数：<input class="count" value="25"></div>' +
      ' <div class="label"><button class="confirm">确认创建</button><button class="cancel">取消创建</button></div>' +
      ' <div class="result"></div>' +
      '</div>'
    ).appendTo(document.body),
    resultEl = createThemeEl.find('.result'),
    timers = [] // 定时器

  // 写入样式
  let styleStr = '', styles = ''
  Object.keys(style).forEach(selector => {
    styles = ''
    Object.keys(style[selector]).forEach((styleName, index) => {
      styles += `${styleName}:${style[selector][styleName]};`
    })
    styleStr += `${selector}{${styles}}`
  })
  $(document.body).append(`<style>${styleStr}</style>`)

  // 打开创建主题
  $('#right_header').prepend(openCreateThemeBtn)
  openCreateThemeBtn.click(() => { createThemeEl.toggle() })

  // 创建主题
  createThemeEl.find('.confirm').click(() => {
    var themeName = createThemeEl.find('.theme').val(),
      start = createThemeEl.find('.start').val(),
      count = createThemeEl.find('.count').val()
    if (themeName && start && count) {
      createTheme(themeName, start, count)
    } else {
      alert('请输入' + [themeName ? '' : '主题名称', start ? '' : '开始序号', count ? '' : '创建个数',].join('、'))
    }
  })

  // 取消创建
  createThemeEl.find('.cancel').click(function () {
    createThemeEl.hide()
    timers.forEach(function (timer) {
      clearTimeout(timer)
    })
  })

  // 创建主题
  function createTheme (themeName, start, count) {
    // 创建方法
    function createThemeFunction (tName) {
      $.post('index.php?app=research&mod=Index&act=saveInfo', {
        accessType: 0, attachids: '', res_des: '',
        tag_ids: '', to_space: 1, userids: '|',
        res_name: tName
      }, res => {
        res = JSON.parse(String(res || '{}'))
        res.status == 1
          ? resultEl.append(`<p>${ resultEl.find('p').length } ${ tName } 创建成功 ${ res.credit_info }</p>`)
          : resultEl.append(`<p>${ resultEl.find('p').length } ${ tName } ${ res.credit_info }</p>`)
      })
    }

    // 签到
    $.post(U('widget/CheckIn/check_in'), {}, () => {
      resultEl.append('<p>签到成功！</p>')
    })

    start = start || 1
    count = count || 25
    for (let i = 0; i < count; i++) {
      // 500ms发送一个请求
      timers[i] = setTimeout(() => {
        const num = i + Number(start)
        let newThemeName = themeName + (num === 1 ? '' : num)
        $.post('index.php?app=research&mod=Index&act=IsExistsByTitle', { title: newThemeName },
          status => {
            status == 1
              ? resultEl.append(`<p>${ resultEl.find('p').length } ${ newThemeName } <span style="color: red">您已发布相同主题,请勿重复发布</span></p>'`)
              : status == 0 ? createThemeFunction(newThemeName) : alert('网络错误')
          }
        )
      }, 500 * i)
    }
  }
})();


// 书签脚本
javascript:"use strict";!function(){function e(e,t,n){function i(e){$.post("index.php?app=research&mod=Index&act=saveInfo",{accessType:0,attachids:"",res_des:"",tag_ids:"",to_space:1,userids:"|",res_name:e},function(t){t=JSON.parse(String(t||"{}")),1==t.status?a.append("<p>"+a.find("p").length+" "+e+" 创建成功 "+t.credit_info+"</p>"):a.append("<p>"+a.find("p").length+" "+e+" "+t.credit_info+"</p>")})}$.post(U("widget/CheckIn/check_in"),{},function(){a.append("<p>签到成功！</p>")}),t=t||1,n=n||25;for(var s=0;s<n;s++)!function(n){c[n]=setTimeout(function(){var c=n+Number(t),s=e+(1===c?"":c);$.post("index.php?app=research&mod=Index&act=IsExistsByTitle",{title:s},function(e){1==e?a.append("<p>"+a.find("p").length+" "+s+' <span style="color: red">您已发布相同主题,请勿重复发布</span></p>\''):0==e?i(s):alert("网络错误")})},500*n)}(s)}var t={".createTheme":{position:"fixed",left:"50%",top:"50%",padding:"20px",display:"block",width:"460px",transform:"translate(-50%, -50%)",background:"#0089AA",color:"#fff",overflow:"auto","font-size":"16px","border-radius":"18px"},".createTheme .label":{"margin-bottom":"10px","text-align":"center"},".createTheme p":{"margin-bottom":"5px"},".createTheme input":{padding:"3px 6px"},".createTheme button":{margin:"0 5px",padding:"6px",cursor:"pointer"},".createTheme .result":{"text-align":"center","font-size":"12px"}},n=$('<a class="fr" href="javascript:void(0)">创建主题</a>'),i=$('<div class="createTheme" style="max-height:'+(window.innerHeight-40)+'px"> <div class="label">主题名称：<input class="theme"></div> <div class="label">开始序号：<input class="start" value="1"></div> <div class="label">创建个数：<input class="count" value="25"></div> <div class="label"><button class="confirm">确认创建</button><button class="cancel">取消创建</button></div> <div class="result"></div></div>').appendTo(document.body),a=i.find(".result"),c=[],s="",o="";Object.keys(t).forEach(function(e){o="",Object.keys(t[e]).forEach(function(n,i){o+=n+":"+t[e][n]+";"}),s+=e+"{"+o+"}"}),$(document.body).append("<style>"+s+"</style>"),$("#right_header").prepend(n),n.click(function(){i.toggle()}),i.find(".confirm").click(function(){var t=i.find(".theme").val(),n=i.find(".start").val(),a=i.find(".count").val();t&&n&&a?e(t,n,a):alert("请输入"+[t?"":"主题名称",n?"":"开始序号",a?"":"创建个数"].join("、"))}),i.find(".cancel").click(function(){i.hide(),c.forEach(function(e){clearTimeout(e)})})}();
